package files

import (
	"fmt"
	"io/ioutil"
	"os"
)

func TestFile01() {
	fmt.Println("Hello, File01!")
	// 测试文件读写
	content := "测试文件读写内容"
	err := WriteFile("test.txt", content)
	if err != nil {
		fmt.Println("写入文件错误:", err)
	}

	readContent, err := ReadFile("test.txt")
	if err != nil {
		fmt.Println("读取文件错误:", err)
	} else {
		fmt.Println("读取到的内容:", readContent)
	}
}

func ReadFile(filename string) (string, error) {
	data, err := ioutil.ReadFile("testfiles/" + filename)
	if err != nil {
		return "", err
	}
	return string(data), nil
}

func WriteFile(filename string, content string) error {
	if err := os.MkdirAll("testfiles", os.ModePerm); err != nil {
		return err
	}
	return ioutil.WriteFile("testfiles/"+filename, []byte(content), os.ModePerm)
}
